<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 方法1
    var list = {
      "老牛": function () {
        console.log(1);
      },
      "老虎": function () {
        console.log(2);
      },
      "老猪": function () {
        console.log(3);
      },
      "老马": function () {
        console.log(4);
      },
    }
    var limt = false;
    function fun(name) {
      if (list[name]) {
        list[name]()
        limt =true
      }else{
        console.log("1110");
      }
    }
    fun("老牛")
    // 方法2
    var list2 =[
      ["老牛1",function () {
        console.log(11);
      }],
      ["老虎1",function () {
        console.log(22);
      }]
    ]
    var limt = false;
    function fan(name) {
      for (let i = 0; i < list2.length; i++) {
        if (list2[i][0]===name) {
          list2[i][1]()
          limt =true
        }
      }if(!limt){
          console.log("1120");
        }
    }
    fan("老虎1")
  </script>
</body>
</html>